package com.kuangchi.weixin.sginin.service.Impl;

import com.alibaba.excel.util.StringUtils;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kuangchi.weixin.sginin.dao.DealWIthDao;
import com.kuangchi.weixin.sginin.dao.PageDemo;
import com.kuangchi.weixin.sginin.service.IDealWIthService;
import com.kuangchi.weixin.sginin.vo.GetPakge;
import com.kuangchi.weixin.sginin.vo.KcSgininExcelVo;
import com.kuangchi.weixin.sginin.vo.KcSgininVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * @version v1.0
 * @类描述：
 * @项目名称：
 * @包名： com.kuangchi.weixin.sginin.service.Impl
 * @类名称：SgininService
 * @创建人：YIHANG.XU
 * @创建时间：2020/10/1310:58 下午
 * @修改人：YIHANG.XU
 * @修改时间：2020/10/1310:58 下午
 * @修改备注：
 * @Copyright
 */
@Service
public class DealWIthService implements IDealWIthService {
    @Autowired
    DealWIthDao dealWIthDao;
    @Autowired
    PageDemo pageDemo;

    /**
     * 用户登记
     *
     * @param kcSgininVo
     */
    @Override
    public String userSignUp(KcSgininVo kcSgininVo) {

        Map<String, String> map = new HashMap<>();
        try {
            int count = dealWIthDao.getUserCount(kcSgininVo);
            if (count > 0) {
                map.put("code", "10002");
                map.put("message", "你已经注册");
            }else {
                dealWIthDao.userSignUp(kcSgininVo);
            }

        } catch (Exception e) {
            map.put("code", "10001");
            map.put("message", "网络出现问题，请联系现场工作人员。");
        }

        return JSON.toJSONString(map);

    }

    /**
     * 查询签到人员信息
     *
     * @param openId
     * @return
     */
    @Override
    public List<KcSgininVo> getUserVo(String openId) {
        if (openId == null && openId.length() == 0){
            return null;
        }
        return dealWIthDao.getUserVo(openId);
    }

    /**
     * 用户签到
     *
     * @param openId
     */
    @Override
    public String userSignIn(String openId) {
        Map<String, String> map = new HashMap<>();
        if (openId == null && openId.length() == 0){
            map.put("code", "10000");
            map.put("message", "传输信息存在问题");
            return JSON.toJSONString(map);
        }else {
            map.put("code", "200");
            map.put("message", "签到成功");
            dealWIthDao.userSignIn(openId);
            return JSON.toJSONString(map);
        }

    }

    @Override
    public List<KcSgininExcelVo> getExcelData() {
        return dealWIthDao.getExcelData();
    }

    @Override
    public int getParkingCount() {
        return dealWIthDao.getParkingCount();
    }

    @Override
    public void getPage() {
        IPage<GetPakge> page =  new Page<>(1,10);

        QueryWrapper<GetPakge> wrapper = new QueryWrapper<>();
       if(!StringUtils.isEmpty("aa")){
            wrapper.eq("id","1");
        }if(!StringUtils.isEmpty("11")){
            wrapper.and(Wrapper ->Wrapper.eq("name","2").or().eq("id","1"));

        }

        IPage<GetPakge> getPakgeIPage = pageDemo.selectPage(page, wrapper);
        System.out.println(getPakgeIPage);
    }
}
